import { UserProfilesAPI } from '@/request/api'
export default {
    namespaced: true,
    state: {
        // 用户信息
        userInfo: {
            //昵称
            nickName: 'Caidanzi',
            coin: 555,
            headImg: require('../../assets/img/service.848ec511.png')
        },
        // 购物车数量
        cartTotal: 55
    },
    mutations: {
        // 修改用户信息
        changeUserInfo(state, payload) {
            // console.log('修改了登录状态');
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        // 初始化用户信息的方法
        initUserInfo(state) {
            state.userInfo = {
                nickName: 'Caidanzi',
                coin: 555,
                headImg: require('../../assets/img/service.848ec511.png')
            }
            state.cartTotal = 55
        }
    },
    actions: {
        async asyncChangeUserInfo(context) {
            // 获取用户信息  异步
            let user = await UserProfilesAPI();
            console.log('asyncChangeUserInfo555:', user);
            // 调用mutaions方法 , 更新数据
            context.commit('changeUserInfo', user.data)
        }
    }
}